package cn.handong.tool.Java文件操作.excel;

import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MedalDistributionImpl implements MedalDistributionService {


    @Override
    public HSSFWorkbook downloadMedalDetailList(){
        //Workbook
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("导入结果_" + "2023-4-13");
        // 新增数据行，并且设置单元格数据
        int rowNum = 1;
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = {"序号", "会员体系", "会员卡号", "操作类型", "勋章名称", "发放时间", "勋章调整状态", "错误原因","用户ID","手机号"};
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = row.createCell(i);
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);
        }

        //在表中存放查询到的数据放入对应的列
        if (true) {
            for (int i = 0 ; i < 10 ; i++) {
                HSSFRow row1 = sheet.createRow(rowNum);
                row1.createCell(0).setCellValue(rowNum);
                row1.createCell(1).setCellValue("会员-体系");
                row1.createCell(2).setCellValue("会员-卡号");
                row1.createCell(3).setCellValue("操作-类型");
                row1.createCell(4).setCellValue("勋章-名称");
                row1.createCell(5).setCellValue("Empty Field");
                row1.createCell(6).setCellValue("发放成功");
                row1.createCell(7).setCellValue("错误-原因");
                row1.createCell(8).setCellValue("用户-ID");
                row1.createCell(9).setCellValue("手机号");
                rowNum++;
            }
        }
        //返回值
        return workbook;
    }

}
